//
//  CollectItemController.m
//  SleepingElf
//
//  Created by karong on 2023/10/25.
//

#import "CollectItemController.h"
#import "CollectRequest.h"
#import "CollectItemCell.h"

@interface CollectItemController ()
@property (weak, nonatomic) IBOutlet UICollectionView *listView;
@end

@implementation CollectItemController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.clearColor;
    CollectRequest * request = [CollectRequest new];
    self.request = request;
    [self addObserver];
}

- (void)addObserver {
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(beginRefresh) name:SELoginSuccessNotification object:nil];
}

- (BOOL)disableAutoBeginRefresh {
    return YES;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CollectItemCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectItemCell" forIndexPath:indexPath];
    [cell setDataWithObject:self.dataArray[indexPath.row] type:self.type];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = CGSizeZero;
    size.width = SEScreenWidth - 13 - 13;
    size.height = 74;
    return size;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(collectItemControllerDidSelectWithObject:)]) {
        [self.delegate collectItemControllerDidSelectWithObject:self.dataArray[indexPath.row]];
    }
    [self.listView reloadData];
}
@end
